//有序数组的平方
/*给你一个按 非递减顺序 排序的整数数组 nums，返回 每个数字的平方 组成的新数组，要求也按 非递减顺序 排序。*/
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* sortedSquares(int* nums, int numsSize, int* returnSize) {
    int count = 0;
    *returnSize=numsSize;
    while (count<numsSize&&nums[count] < 0) {
        count++;
    }
    int n1 = count - 1;
    int n2 = count;
    int* _nums = (int*)malloc(numsSize * sizeof(int));
    int* new_nums = _nums;
    while (n1 >= 0 && n2 < numsSize) {
        if (nums[n1] * nums[n1] < nums[n2] * nums[n2]) {
            *new_nums = nums[n1] * nums[n1];
            new_nums++;
            n1--;
        } else {
            *new_nums = nums[n2] * nums[n2];
            new_nums++;
            n2++;
        }
    }
    while(n1>=0)
    {
        *new_nums=nums[n1]*nums[n1];
            new_nums++;
            n1--;
    }
    while(n2<numsSize)
    {
        *new_nums=nums[n2]*nums[n2];
            new_nums++;
            n2++;
    }
    return _nums;
}